<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:event listener="#{usuarioBean.pesquisar()}" type="postAddToView" />
				<f:event listener="#{usuarioBean.carregaTreeNodes()}" type="postAddToView" />
			</f:metadata>
			
			<p:panel header="#{msg['massai.permissao.header']}">
				<h:panelGrid cellspacing="3" cellpadding="0">
					<h:panelGrid columns="2">
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.permissao.login']}" for="login" />
							<p:inputText tabindex="1" value="#{usuarioBean.usuario.login}" id="login" 
								label="#{msg['massai.permissao.login']}" style="width: 130px;" maxlength="20">
								<p:ajax event="change" listener="#{usuarioBean.usuarioPorLogin()}" update="form" />
							</p:inputText>
						</h:panelGrid>

						<h:panelGrid columns="2" style="padding: 18px 10px 0 10px;">
							<p:selectBooleanCheckbox immediate="true" tabindex="2" 
								value="#{usuarioBean.admin}" id="admin" label="#{msg['massai.usuario.administrador']}">
								<p:ajax event="change" listener="#{usuarioBean.roleAdmin()}" update="form,:messages" />
							</p:selectBooleanCheckbox>
							<h:outputLabel value="#{msg['massai.usuario.administrador']}" for="admin" />
						</h:panelGrid>
					</h:panelGrid>
					
					<h:panelGrid id="panelPermissoes" rendered="#{!usuarioBean.admin}">
						<p:tree value="#{usuarioBean.root}" var="permissoes" selectionMode="checkbox"
							animate="true" propagateSelectionDown="true" propagateSelectionUp="true" 
							selection="#{usuarioBean.nodesSelecionados}" style="margin-top: 30px;">
							<p:treeNode expandedIcon="ui-icon ui-icon-folder-open" collapsedIcon="ui-icon ui-icon-folder-collapsed">
								<h:outputText value="#{permissoes.descricao}"/>
							</p:treeNode>
							<p:treeNode type="document" icon="ui-icon ui-icon-document">
								<h:outputText value="#{permissoes.descricao}" />
							</p:treeNode>
						</p:tree>
					</h:panelGrid>
				</h:panelGrid>
				
				<h:panelGrid style="margin-top: 10px;">
					<p:commandButton tabindex="3" value="#{msg['massai.comum.salvar']}"
						actionListener="#{usuarioBean.salvarPermissao()}" ajax="false" />
				</h:panelGrid>
			</p:panel>
			
			<p:dataTable style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
				value="#{usuarioBean.listaUsuarios}" var="user" sortMode="multiple" rows="5" paginator="true"
                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

				<f:facet name="header"><h:outputText value="#{msg['massai.usuario.usuarios']}" /></f:facet>
				
				<p:column headerText="#{msg['massai.manterGrupoProducao.codigo']}" sortBy="#{user.id}" width="60">
					<h:outputText value="#{genericUtilBean.completarZerosEsquerda(user.id, 6)}" />
				</p:column>
				
				<p:column headerText="#{msg['massai.usuario.nome']}" sortBy="#{user.nome}">
					<h:outputText value="#{user.nome}" />
				</p:column>
				
				<p:column headerText="#{msg['massai.usuario.login']}" sortBy="#{user.login}" width="120">
					<h:outputText value="#{user.login}" />
				</p:column>
				
				<p:column headerText="#{msg['massai.usuario.status']}" sortBy="#{user.ativo}" width="100">
					<h:outputText value="#{user.ativo.descricao}" />
				</p:column>
				
				<p:column headerText="#{msg['massai.comum.editar']}" width="32" style="text-align: center;">
					<p:commandLink actionListener="#{usuarioBean.atualizarPermissoes()}" update=":form">
						<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_edit.png" 
							width="16" height="16" border="0" name="#{msg['massai.comum.editar']}" 
							title="#{msg['massai.comum.editar']}" alt="#{msg['massai.comum.editar']}" />
						<f:param name="id" value="#{user.id}" />
					</p:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>
</html>